/*保持所有列表标题*/
var $titWrap = mui("#sort-title .mui-scroll");
var $titItem = mui("#sort-title .mui-scroll .mui-control-item");

/*分类列表动态逻辑*/
mui.each($titItem,function(index,item){
	item.onclick=function(){
		var _index =parseInt(this.getAttribute("data-index"));
		var gallery = mui('.sort-list.mui-slider');
		gallery.slider().gotoItem(_index); //跳转到第index张图片，index从0开始；
	}
	  mui(item).on("tap",function(){
	  	var _index =parseInt(this.getAttribute("data-index"));
		var gallery = mui('.sort-list.mui-slider');
		gallery.slider().gotoItem(_index); //跳转到第index张图片，index从0开始；
	  });
}) ;

/*点击切换到相应的滚动条里面*/
$titItem.on("tap", function() {
	console.log(this);
	var gallery = mui('.sort-list.mui-slider');
	gallery.slider().gotoItem(this.index); //跳转到第index张图片，index从0开始；
});
/*监听事件*/
document.querySelector('.mui-slider.sort-list').addEventListener('slide', function(event) {
	/*关联导航滚动事件*/
	this.style.height =this.querySelectorAll(".mui-slider-item.mui-control-content")[event.detail.slideNumber].offsetHeight + "px";
	 titLocaltion(event.detail.slideNumber);
	 //console.log( );
	//if (event.detail.slideNumber === 1&&!item2Show) {
	//  //切换到第二个选项卡
	//  //根据具体业务，动态获得第二个选项卡内容；
	//  var content =" ...."
	//  console.log(1);
	//  //显示内容
	//  //document.getElementById("item2").innerHTML = content;
	//  //改变标志位，下次直接显示
	//  item2Show = true;
	//} else if (event.detail.slideNumber === 2&&!item3Show) {
	//  //切换到第三个选项卡
	//  //根据具体业务，动态获得第三个选项卡内容；
	//  var content = "...."
	//  console.log(2);
	//  //显示内容
	//  //document.getElementById("item3").innerHTML = content;
	//  //改变标志位，下次直接显示
	//  item3Show = true;
	//}
});

/*关联导航滚动事件*/
function titLocaltion(num) {
	for(var i = 0; i < $titItem.length; i++) {
		var myclassName = $titItem[i].className
		if(myclassName.indexOf("mui-active") >= 0) {
			$titItem[i].className = myclassName.replace(/mui-active/g, "")
		}
	}
	$titItem[num].className = $titItem[num].className + " mui-active";
	if($titItem[num].className.indexOf("  ") > 0) {
		$titItem[num].className = $titItem[num].className.replace("  ", " ");
	}
	/*窗口的距离*/
	var leftDis = $titItem[num].offsetLeft - 184;
	if(leftDis >= 0 && num != $titItem.length - 1) {
		mui('#sort-title').scroll().scrollTo(-leftDis, 0);
	}
}
/*渲染轮播*/
mui.ajax('http://xhwed.com/xhwe.php/HomePage/carousel', {
	dataType: 'json', //服务器返回json格式数据
	type: 'post', //HTTP请求类型
	timeout: 10000, //超时时间设置为10秒；
	headers: {
		'Content-Type': 'application/json'
	},
	success: function(data) {
		//服务器返回响应，根据响应结果，分析是否登录成功；
		//console.log(data);
		var slider = {};
		slider["carousel"] = data.result.carousel;
		slider["length"] = data.result.carousel.length - 1;
		var html = template("sliderJs", slider);
		mui("#sliderwrap")[0].innerHTML = html;
		//手动调用图片轮播的初始化方法
		var gallery = mui('#slider');
		gallery.slider({
			interval: 3000 //自动轮播周期，若为0则不自动播放，默认为0；
		});
	},
	error: function(xhr, type, errorThrown) {
		//异常处理；
		//console.log(type);
		//console.log(xhr);
	}
});


/*渲染婚礼策划*/
mui.ajax('http://xhwed.com/xhwe.php/Plan/planList', {
	dataType: 'json', //服务器返回json格式数据
	type: 'post', //HTTP请求类型
	timeout: 10000, //超时时间设置为10秒；
	headers: {
		'Content-Type': 'application/json'
	},
	success: function(data) {
		//console.log(data);
		var html = template("hlchJs", data.result);
		mui("#hlchwrap")[0].innerHTML = html;
		document.querySelector('.mui-slider.sort-list').style.height = document.querySelector(".mui-slider-item.mui-control-content").offsetHeight + "px";
		
	},
	error: function(xhr, type, errorThrown) {
		//异常处理;
		//console.log(type);
		//console.log(xhr);
	}
});

/*渲染婚纱摄影*/
mui.ajax('http://xhwed.com/xhwe.php/Photography/packageList', {
	dataType: 'json', //服务器返回json格式数据
	type: 'post', //HTTP请求类型
	timeout: 10000, //超时时间设置为10秒；
	headers: {
		'Content-Type': 'application/json'
	},
	success: function(data) {
		//console.log(data);
		var html = template("hscyJs", data.result);
		mui("#hscywrap")[0].innerHTML = html;
	},
	error: function(xhr, type, errorThrown) {
		//异常处理;
		//console.log(type);
		//console.log(xhr);
	}
});
/*渲染酒店预定*/
mui.ajax('http://xhwed.com/xhwe.php/Hotel/hotelList', {
	dataType: 'json', //服务器返回json格式数据
	type: 'post', //HTTP请求类型
	timeout: 10000, //超时时间设置为10秒；
	headers: {
		'Content-Type': 'application/json'
	},
	success: function(data) {
		//console.log(data);
		var html = template("jdydJs", data.result);
		mui("#jdydwrap")[0].innerHTML = html;
	},
	error: function(xhr, type, errorThrown) {
		//异常处理;
		//console.log(type);
		//console.log(xhr);
	}
});
/*渲染蜜月旅行*/
mui.ajax('http://xhwed.com/xhwe.php/Honeymoon/honeymoonList', {
	dataType: 'json', //服务器返回json格式数据
	type: 'post', //HTTP请求类型
	timeout: 10000, //超时时间设置为10秒；
	headers: {
		'Content-Type': 'application/json'
	},
	success: function(data) {
		//console.log(data);
		var html = template("mylxJs", data.result);
		mui("#mylxwrap")[0].innerHTML = html;
	},
	error: function(xhr, type, errorThrown) {
		//异常处理;
		//console.log(type);
		//console.log(xhr);
	}
});

/*渲染婚礼主持*/
mui.ajax('http://xhwed.com/xhwe.php/Compere/compereList', {
	dataType: 'json', //服务器返回json格式数据
	type: 'post', //HTTP请求类型
	timeout: 10000, //超时时间设置为10秒；
	headers: {
		'Content-Type': 'application/json'
	},
	success: function(data) {
		//console.log(data);
		var html = template("hlzcJs", data);
		mui("#hlzcwrap")[0].innerHTML = html;
	},
	error: function(xhr, type, errorThrown) {
		//异常处理;
		//console.log(type);
		//console.log(xhr);
	}
});

/*渲染婚礼化妆*/
mui.ajax('http://xhwed.com/xhwe.php/Makeup/makeupList', {
	dataType: 'json', //服务器返回json格式数据
	type: 'post', //HTTP请求类型
	timeout: 10000, //超时时间设置为10秒；
	headers: {
		'Content-Type': 'application/json'
	},
	success: function(data) {
	//	console.log(data);
		var html = template("hlhzJs", data);
		mui("#hlhzwrap")[0].innerHTML = html;
	},
	error: function(xhr, type, errorThrown) {
		//异常处理;
		//console.log(type);
		//console.log(xhr);
	}
});

/*渲染婚礼摄影*/
mui.ajax('http://xhwed.com/xhwe.php/Shoot/shootList', {
	dataType: 'json', //服务器返回json格式数据
	type: 'post', //HTTP请求类型
	timeout: 10000, //超时时间设置为10秒；
	headers: {
		'Content-Type': 'application/json'
	},
	success: function(data) {
	//	console.log(data);
		var html = template("hlcyJs", data);
		mui("#hlcywrap")[0].innerHTML = html;
	},
	error: function(xhr, type, errorThrown) {
		//异常处理;
		//console.log(type);
		//console.log(xhr);
	}
});

/*渲染婚礼摄像*/
mui.ajax('http://xhwed.com/xhwe.php/Camera/cameraList', {
	dataType: 'json', //服务器返回json格式数据
	type: 'post', //HTTP请求类型
	timeout: 10000, //超时时间设置为10秒；
	headers: {
		'Content-Type': 'application/json'
	},
	success: function(data) {
		//console.log(data);
		var html = template("hlcxJs", data);
		mui("#hlcxwrap")[0].innerHTML = html;
	},
	error: function(xhr, type, errorThrown) {
		//异常处理;
		//console.log(type);
		//console.log(xhr);
	}
});